using System;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;

using XPTable;
using XPTable.Editors;
using XPTable.Models;

namespace View
{
	/// <summary>
	/// Summary description for AddPayeeDialog.
	/// </summary>
	public class EditUserProfile : System.Windows.Forms.Form
	{
		private System.Windows.Forms.Label label1;
		private System.Windows.Forms.Label label2;
		private System.Windows.Forms.Label label3;
		private PinkieControls.ButtonXP cancelButton;
		private XPTable.Models.Table payeesTable;
		private System.Windows.Forms.Label totalAmountLabel;
		private System.Windows.Forms.TextBox confirmPasswordField;
		/// <summary>
		/// Required designer variable.
		/// </summary>
		private System.ComponentModel.Container components = null;
		private Model.UserManager manager;
		private PinkieControls.ButtonXP updateButton;
		private System.Windows.Forms.TextBox newPasswordField;
		private System.Windows.Forms.TextBox oldPasswordField;
		private Model.UserIdentity newUser;

		public EditUserProfile(Model.UserManager m)
		{

			manager = m;

			//
			// Required for Windows Form Designer support
			//
			InitializeComponent();

			//
			// TODO: Add any constructor code after InitializeComponent call
			//
		}

		/// <summary>
		/// Clean up any resources being used.
		/// </summary>
		protected override void Dispose( bool disposing )
		{
			if( disposing )
			{
				if(components != null)
				{
					components.Dispose();
				}
			}
			base.Dispose( disposing );
		}

		#region Windows Form Designer generated code
		/// <summary>
		/// Required method for Designer support - do not modify
		/// the contents of this method with the code editor.
		/// </summary>
		private void InitializeComponent()
		{
			this.label1 = new System.Windows.Forms.Label();
			this.label2 = new System.Windows.Forms.Label();
			this.newPasswordField = new System.Windows.Forms.TextBox();
			this.label3 = new System.Windows.Forms.Label();
			this.confirmPasswordField = new System.Windows.Forms.TextBox();
			this.cancelButton = new PinkieControls.ButtonXP();
			this.updateButton = new PinkieControls.ButtonXP();
			this.oldPasswordField = new System.Windows.Forms.TextBox();
			this.SuspendLayout();
			// 
			// label1
			// 
			this.label1.Location = new System.Drawing.Point(16, 32);
			this.label1.Name = "label1";
			this.label1.Size = new System.Drawing.Size(80, 16);
			this.label1.TabIndex = 0;
			this.label1.Text = "Old password:";
			// 
			// label2
			// 
			this.label2.Location = new System.Drawing.Point(16, 64);
			this.label2.Name = "label2";
			this.label2.Size = new System.Drawing.Size(88, 23);
			this.label2.TabIndex = 2;
			this.label2.Text = "New password:";
			// 
			// newPasswordField
			// 
			this.newPasswordField.Location = new System.Drawing.Point(112, 64);
			this.newPasswordField.Name = "newPasswordField";
			this.newPasswordField.PasswordChar = '*';
			this.newPasswordField.Size = new System.Drawing.Size(152, 20);
			this.newPasswordField.TabIndex = 3;
			this.newPasswordField.Text = "";
			// 
			// label3
			// 
			this.label3.Location = new System.Drawing.Point(16, 96);
			this.label3.Name = "label3";
			this.label3.Size = new System.Drawing.Size(104, 23);
			this.label3.TabIndex = 4;
			this.label3.Text = "Confirm password:";
			// 
			// confirmPasswordField
			// 
			this.confirmPasswordField.Location = new System.Drawing.Point(112, 96);
			this.confirmPasswordField.Name = "confirmPasswordField";
			this.confirmPasswordField.PasswordChar = '*';
			this.confirmPasswordField.Size = new System.Drawing.Size(152, 20);
			this.confirmPasswordField.TabIndex = 5;
			this.confirmPasswordField.Text = "";
			// 
			// cancelButton
			// 
			this.cancelButton.BackColor = System.Drawing.Color.FromArgb(((System.Byte)(0)), ((System.Byte)(224)), ((System.Byte)(223)), ((System.Byte)(227)));
			this.cancelButton.DefaultScheme = true;
			this.cancelButton.DialogResult = System.Windows.Forms.DialogResult.None;
			this.cancelButton.Hint = "";
			this.cancelButton.Location = new System.Drawing.Point(149, 144);
			this.cancelButton.Name = "cancelButton";
			this.cancelButton.Scheme = PinkieControls.ButtonXP.Schemes.Silver;
			this.cancelButton.Size = new System.Drawing.Size(104, 24);
			this.cancelButton.TabIndex = 20;
			this.cancelButton.Text = "Cancel";
			this.cancelButton.Click += new System.EventHandler(this.cancelButton_Click);
			// 
			// updateButton
			// 
			this.updateButton.BackColor = System.Drawing.Color.FromArgb(((System.Byte)(0)), ((System.Byte)(224)), ((System.Byte)(223)), ((System.Byte)(227)));
			this.updateButton.DefaultScheme = true;
			this.updateButton.DialogResult = System.Windows.Forms.DialogResult.None;
			this.updateButton.Hint = "";
			this.updateButton.Location = new System.Drawing.Point(37, 144);
			this.updateButton.Name = "updateButton";
			this.updateButton.Scheme = PinkieControls.ButtonXP.Schemes.Silver;
			this.updateButton.Size = new System.Drawing.Size(104, 24);
			this.updateButton.TabIndex = 19;
			this.updateButton.Text = "Update";
			this.updateButton.Click += new System.EventHandler(this.addButton_Click);
			// 
			// oldPasswordField
			// 
			this.oldPasswordField.Location = new System.Drawing.Point(112, 32);
			this.oldPasswordField.Name = "oldPasswordField";
			this.oldPasswordField.PasswordChar = '*';
			this.oldPasswordField.Size = new System.Drawing.Size(152, 20);
			this.oldPasswordField.TabIndex = 1;
			this.oldPasswordField.Text = "";
			// 
			// EditUserProfile
			// 
			this.AutoScaleBaseSize = new System.Drawing.Size(5, 13);
			this.ClientSize = new System.Drawing.Size(290, 184);
			this.Controls.Add(this.oldPasswordField);
			this.Controls.Add(this.cancelButton);
			this.Controls.Add(this.updateButton);
			this.Controls.Add(this.confirmPasswordField);
			this.Controls.Add(this.newPasswordField);
			this.Controls.Add(this.label3);
			this.Controls.Add(this.label2);
			this.Controls.Add(this.label1);
			this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.FixedToolWindow;
			this.Name = "EditUserProfile";
			this.StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen;
			this.Text = "Edit user profile";
			this.ResumeLayout(false);

		}
		#endregion


		private void cancelButton_Click(object sender, System.EventArgs e)
		{
			this.Dispose();
		}

		private void addButton_Click(object sender, System.EventArgs e)
		{
			try
			{

				if(oldPasswordField.Text != manager.CurrentUserID.Password)
				{
					MessageBox.Show("Invalid user password entered.");
				}
				else if(newPasswordField.Text != confirmPasswordField.Text)
				{
					MessageBox.Show("Passwords do not match.");
				}
				else
				{
					manager.ChangePassword(newPasswordField.Text);
					MessageBox.Show("Password successfully changed");
					this.Dispose();
				}
			}
			catch(Exception exp)
			{
				MessageBox.Show(exp.Message);
			}
				
		}
	}
}
